using System;
using System.Web;

using PlugNT.Cms.Page;

namespace PlugNT.App.Bbs.Page
{
    public class BasePager : SitePager
    {
        protected override void OnPreRenderComplete(EventArgs e)
        {
            PlugNT.Cms.BLL.User.DelOnlineUser();
            PlugNT.Cms.BLL.User.CpuMaxOnline();

            base.OnPreRenderComplete(e);
        }

        public override bool IsLogined()
        {
            string username = PlugNT.Cms.Custom.KeyFlags.SessionUser;
            string usercode = PlugNT.Cms.Custom.KeyFlags.CookieUserCode;
            if (Session[username] == null)
            {
                string uCode = PlugNT.Common.Utils.GetCookie(usercode);
                if (uCode != "")
                {
                    string[] cArr = uCode.Split('|');
                    if (cArr.Length == 2)
                    {
                        string eCode = PlugNT.Cms.Custom.SysManager.GetLongNoString();
                        string err = "";
                        if (PlugNT.Cms.BLL.User.Login(cArr[0], cArr[1], eCode, out err))
                        {
                            new PlugNT.Cms.BLL.User().Logined(cArr[0]);

                            PlugNT.Common.Utils.SetCookie(usercode, cArr[0] + "|" + eCode);
                            return true;
                        }
                        else
                        {
                            PlugNT.Common.Utils.SetCookie(usercode, "");
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return true;
            }

        }

    }
}

